package com.woniu.login.controller;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.common.dto.LoginDto;
import com.woniu.common.entity.AdmAccount;
import com.woniu.common.entity.AdmEmployee;
import com.woniu.common.entity.Result;
import com.woniu.login.service.AccountService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class AccountController {
    @Autowired
    AccountService accountService;
    //  查询所有账号
    @PostMapping("/account/getall/{pageIndex}/{pageSize}")
    public Result<IPage<AdmAccount>> getAll(
            @PathVariable("pageIndex") int pageIndex,
            @PathVariable("pageSize") int pageSize,
            @RequestBody AdmAccount admAccount, HttpServletRequest request) {
        System.out.println("传过来的值："+request.getHeader("token"));
        System.out.println("admAccount:"+admAccount);
        IPage<AdmAccount> admAccountIPage = accountService.getAll(pageIndex, pageSize, admAccount);
        return Result.ok(admAccountIPage);
    }
    //  修改账号信息
    @PostMapping("/account/update")
    public Result update(@RequestBody AdmAccount admAccount, HttpServletRequest request) {
        System.out.println("admAccount:"+admAccount);
        return accountService.update(admAccount);
    }

}
